const formRules = require("../util/formRules.js");
module.exports = {
	/**
	 * 修改角色
	 * @url admin/system/role/sys/update 前端调用的url参数地址
	 * data 请求参数 说明
	 * @param {String} _id
	 * @param {Boolean} integrals
	 * res 返回参数说明
	 * @param {Number} code 错误码，0表示成功
	 * @param {String} msg 详细信息
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: '' };
		// 业务逻辑开始----------------------------------------------------------- 
		let {
				_id,
				days,
			} = data;
		if(days){
			let user = await vk.baseDao.findById({
				dbName: "uni-id-users",
				id: _id
			})
			let tmpDate = new Date()
			if(user.vip_time && user.vip_time > new Date().getTime()){
				tmpDate.setTime(user.vip_time)
			}
			let endDate = new Date()
			endDate.setTime(tmpDate.getTime() + 24*60*60*1000*days)
			
			let user_id = await vk.baseDao.updateById({
				dbName: "uni-id-users",
				id: user._id,
				dataJson: {
					vip_time: endDate.getTime()
				}
			})
			
			if(!user_id){
				await transaction.rollback();
				return {
					code: -1,
					msg:"开通VIP失败"
				}
			}
		}
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}

}